package No1_100.No21_30.ImplementstrStr_28;

public class Solution {
	/*
	 * 独立完成，判断一个序列是不是另一个序列的子序列
	 * */
    public static int strStr(String haystack, String needle) {
        if(needle.equals("")){
            return 0;
        }
        char[] h = haystack.toCharArray();/////////////       String to char[] 方法需掌握
        char[] n = needle.toCharArray();
        for(int i = 0;i < h.length;i++){
            int j = i,k = 0;
            if(h.length-i<n.length){
                return -1;
            }
            while(k<n.length && j<h.length && h[j] == n[k]){
                // System.out.println(h[j]);
                j++;k++;
            }
            if(k == n.length){
                return i;
            }
        }
        return -1;
    }
    public static void main(String[] args) {
		System.out.println(strStr("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab","aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
		
	}
}
